<?php
$config = new RM_Config();
$currencySymbol = $config->getValue('rm_config_currency_symbol');
$dateFormat = $config->getJSDateformat();

$unitConfig = new RM_UnitHourlyPricesConfig();
$weekendEnabled = $unitConfig->fetchValueByUnit($this->unit->id, 'weekend_price_enabled');

if ($weekendEnabled) {
    $datesWidth = "15%;";
} else {
    $datesWidth = "20%;";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr" id="minwidth" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/userdata/modules/HourlyPrices/css/list.css" />
</head>
<body>
<div class="RM_HourlyPricesList_Header">
    <?php echo $this->unit->name."&nbsp;".$this->_translate->_('User.HourlyPrices.Unit.List','Title');?>
</div>
<div align="center">
    <table class="RM_HourlyPricesList" width="100%" cellpadding="5" cellspacing="0">
    <thead>
        <tr>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','PeriodName');?>
            </th>
            <th width="<?php echo $datesWidth ?>">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','StartDate');?>
            </th>
            <th width="<?php echo $datesWidth ?>">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','EndDate');?>
            </th>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','MinStay');?>
            </th>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','MaxStay');?>
            </th>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','NoPersons');?>
            </th>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','HourlyPrice');?>
            </th>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','WeekdayPrice');?>
            </th>
            <?php if ($weekendEnabled) { ?>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','WeekendPrice');?>
            </th>
            <?php } ?>
            <th width="10%">
                <?php echo $this->_translate->_('User.HourlyPrices.Unit.List','WeeklyPrice');?>
            </th>
        </tr>
    </thead>
    <tbody>
    <?php
    foreach ($this->prices as $key => $price) {
        if ($key % 2 != 0) {
            $rowStyle = "odd";
        } else {
            $rowStyle = "even";
        }
        ?>
        <tr>
            <td align="center" class="<?php echo $rowStyle;?>">
                <?php echo $price->period_name;?>
            </td>
            <td align="center" class="<?php echo $rowStyle;?>">
                <?php echo date($dateFormat, strtotime($price->start_datetime));?>
            </td>
            <td align="center" class="<?php echo $rowStyle;?>">
                <?php echo date($dateFormat, strtotime($price->end_datetime));?>
            </td>
            <td align="center" class="<?php echo $rowStyle;?>">
                <?php
                if ((int)$price->min > 0) {
                    echo $price->min;
                } else {
                    echo $this->_translate->_('User.HourlyPrices.Unit.List','NoRestriction');
                }
                ?>
            </td>
            <td align="center" class="<?php echo $rowStyle;?>">
                <?php
                if ((int)$price->max > 0) {
                    echo $price->max;
                } else {
                    echo $this->_translate->_('User.HourlyPrices.Unit.List','NoRestriction');
                }
                ?>
            </td>
            <td align="center" class="<?php echo $rowStyle;?>">
                <?php echo $price->number_persons;?>
            </td>
            <td align="right" class="<?php echo $rowStyle;?>">
                <?php echo $currencySymbol.$price->hour;?>
            </td>
            <td align="right" class="<?php echo $rowStyle;?>">
                <?php echo $currencySymbol.$price->day;?>
            </td>
            <?php if ($weekendEnabled) { ?>
            <td align="right" class="<?php echo $rowStyle;?>">
                <?php echo $currencySymbol.$price->weekend;?>
            </td>
            <?php } ?>
            <td align="right" class="<?php echo $rowStyle;?>">
                <?php echo $currencySymbol.$price->week;?>
           </td>
        </tr>
        <?php
    }
    ?>
    </tbody>
    </table>
</div>
</body>
</html>